package cn.swust.designpatternlearningplatform.dao.sql;

import cn.swust.designpatternlearningplatform.domain.entity.TrainingPaper;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.jdbc.SQL;
@Slf4j
public class StudentTrainingPaperDaoSql {
    public String insertTrainingPaper(TrainingPaper trainingPaper){
        String paperName=trainingPaper.getPaperName();
        String paperNumber=trainingPaper.getPaperNumber();
        String studentNumber=trainingPaper.getStudentNumber();
        return new SQL() {{
            INSERT_INTO("training_paper");
            VALUES("paper_name","#{paperName}");
            VALUES("paper_number","#{paperNumber}");
            VALUES("student_number","#{studentNumber}");
        }}.toString();
    }
    public String getAllTrainingPaper(String studentNumber) {
        log.info(studentNumber);
        return new SQL(){
            {
                SELECT("paper_name","paper_number");
                FROM("training_paper");
                WHERE("student_number=#{studentNumber}");
            }
        }.toString();
    }

    /**
     * @param topicId:
    	 * @param uuid:
    	 * @param studentNumber:
      * @return String
     * @author wang
     * description 在试卷关联表中存下试卷的信息
     * date 2023/5/9 16:37
     */
    public String addPaperInformation(Integer topicId, String uuid, String studentNumber){
        return new SQL(){
            {
                INSERT_INTO("training_paper_concete_content");
                VALUES("topic_id","#{topicId}");
                VALUES("paper_number","#{uuid}");
                VALUES("student_number","#{studentNumber}");
            }
        }.toString();
    }

    public String getTopicId(String paperNumber, String studentNumber){
        return new SQL(){
            {
                SELECT("topic_id");
                FROM("training_paper_concete_content");
                WHERE("paper_number=#{paperNumber}","student_number=#{studentNumber}");
            }
        }.toString();
    }
      public String getOwnAnswer(String paperNumber, Integer integer,String studentNumber){
        return new SQL(){
            {
                SELECT("own_answer");
                FROM("paper_result");
                WHERE("paper_number=#{paperNumber}","topic_id=#{integer}","student_number=#{studentNumber}");
            }
        }.toString();
      }

      public String getTrainingPaperTopicId(String testId, String number){
        return new SQL(){
            {
                SELECT("topic_id");
                FROM("training_paper_concete_content");
                WHERE("paper_number=#{testId}","student_number=#{number}");
            }
        }.toString();
      }

}
